package com.house365.core.util.map.google;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyPositionOverlay extends Overlay {

	private GeoPoint geoPoint;
	private Drawable drawable;

	public MyPositionOverlay(GeoPoint geoPoint, Drawable drawable) {
		super();
		this.geoPoint = geoPoint;
		this.drawable = drawable;
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		super.draw(canvas, mapView, shadow);

		Projection projection = mapView.getProjection();
		Point point = new Point();
		if (drawable != null) {
			projection.toPixels(geoPoint, point);
			BitmapDrawable bd = (BitmapDrawable) drawable;
			Bitmap bitmap = bd.getBitmap();
			canvas.drawBitmap(bitmap, point.x - bitmap.getWidth(), point.y
					- bitmap.getHeight(), null);
		} else {
			projection.toPixels(geoPoint, point);
			Paint paint = new Paint();
			paint.setColor(Color.BLUE);
			paint.setAntiAlias(true);
			paint.setStrokeWidth(6.0f);
			paint.setStyle(Style.STROKE);
			canvas.drawCircle(point.x, point.y, 8.0f, paint);

		}

	}

}
